package com.zff.rental.mapstruct.apartment;


import com.zff.rental.entity.apartment.AttachmentEntity;
import com.zff.rental.vo.apartment.attachment.AttachmentVo;
import com.zff.rental.vo.apartment.attachment.EditAttachmentVo;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author HCY
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface AttachmentMapstruct {
    AttachmentMapstruct INSTANCE = Mappers.getMapper(AttachmentMapstruct.class);

    default List<AttachmentEntity> map(List<EditAttachmentVo> attachmentList, Long belongId, Integer belongType) {
        if (attachmentList == null || attachmentList.isEmpty()) {
            return Collections.emptyList();
        }
        return attachmentList.stream().map(vo -> map(vo, belongId, belongType)).collect(Collectors.toList());
    }

    default AttachmentEntity map(EditAttachmentVo vo, Long belongId, Integer belongType) {
        AttachmentEntity attachmentEntity = new AttachmentEntity();
        attachmentEntity.setBelongId(belongId);
        attachmentEntity.setBelongType(belongType);
        attachmentEntity.setObjectKey(vo.getObjectKey());
        attachmentEntity.setFileType(vo.getFileType());
        attachmentEntity.setSerialNumber(vo.getSerialNumber());
        return attachmentEntity;
    }


    List<AttachmentVo> map(List<AttachmentEntity> attachmentList);
}
